<table data-options="fit:true" id="test_manager"></table>

<script>
	$(function(){ 
		var datagrid; 
		datagrid=$('#test_manager').datagrid({   
		    url:'../testServlet',
		    queryParams:{op:"getAllTest"},
		    loadMsg:'数据加载中...',
		    pagination:true,
		    fitColumns:true,
		    rownumbers:true,
		    striped:true,
		    pageNumber:1,
		    sortOrder:'asc',
		    remoteSort:false,//定义是否通过远程服务器对数据排序。
		    sortName:'tid',
		    columns:[[
		    	{field:'tids',title:'',checkbox:true,width:100,align:'center'},   
		        {field:'tid',title:'编号',width:100,align:'center'},   
		        {field:'tname',title:'测试题目',width:100,align:'center'},
		        {field:'tdec',title:'测试描述',width:200,align:'center'},
		        {field:'ttype',title:'测试类型',width:100,align:'center'}    
		    ]],
		    toolbar: [{
		    	text:'添加',
				iconCls: 'icon-add',
				handler: function(){
					$("#add_test").dialog("open");
				}
			},'-',{
				text:'删除',
				iconCls: 'icon-remove',
				handler: function(){
						
				}
			}]   
		});
  
	});
</script>

<div id="add_test" class="easyui-dialog" title="添加测试" style="width:800px;height:600px"
	data-options="iconCls:'icon-add',resizeble:true,modal:true,closed:true">
	<br /><br />
	<form action="" style="float:left;padding-left:20px" id="testInfo" name="testInfo" method="post">
		<p><label>测试题目:</label><input type="text" id="test_name" name="tname"></p>
		<p><label>测试类型:</label>
			<select id="test_type" name="ttype">
				<option>请选择类型</option>
				<option value="爱情">爱情</option>
			</select>
		</p>
		<p><label>测试图片：</label><input type="file" id="timg_show" name="timg" onchange="previewMultipleImage(this,'show_pic')">
			<div name="timg" id="show_pic" style="width:300px;height:200px;border:1px solid #ccc">
			
			</div>
		</p>
		<p><label style="vertical-align: top">测试描述:</label>
			<textarea cols="100" rows="3" name="tdec" id="test_dec"></textarea>
		</p>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="addTest()" style="margin-left:60px;">添加</a>			
	</form>
</div>

<script>
	function addTest(){
		var tname=$("#test_name").val();
		var ttype=$("#test_type").val();
		var tdec=$("#test_dec").val();
		$.ajaxFileUpload({
			url:"../testServlet?op=addTest",
			fileElementId:["timg_show"],
			secureuri:false,
			dataType:'json', 
			data:{
				tname:tname,
				ttype:ttype,
				tdec:tdec
			},
			success:function(data){
				data=parseInt($.trim(data));
				if(data==1 ){
					$.messager.show({
						title:'成功提示',
						msg:'测试添加成功...',
						timeout:3000,
						showType:'slide'
					});
					$('#add_test').dialog("close");
					$('#test_manager').datagrid("reload");
					ue.setContent("");
					$("#show_pic").html("");
					$("#testInfo")[0].reset();
				}else{
					$.messager.alert('错误提示','测试添加失败,请稍后重试...','error');
				}
			}
		});
	}
</script>